import eventBus from "../eventBus/eventBus.js";

const userNameRules = [
  (userName) => !!userName || "用户名不得为空",
  (userName) => /^[a-zA-Z]/.test(userName) || "首位必须为字母",
  (userName) => (userName && userName.length >= 8) || "用户名长度不得小于8位",
  (userName) => (userName && userName.length < 17) || "用户名长度不得大于16位",
  (userName) =>
    /^\w{8,16}$/.test(userName) || "格式不正确。只能包含字母、数字和下划线",
];

const passwordRulse = [
  (password) => !!password || "密码不得为空",
  (password) => (password && password.length >= 8) || "密码长度不得小于8位",
  (password) => (password && password.length < 17) || "密码长度不得大于16位",
  (password) => {
    const r = /(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,16}$/;
    return r.test(password) || "密码格式不正确";
  },
];

export { userNameRules, passwordRulse };
